"""
商品相关API路由
"""

from fastapi import APIRouter, Depends, HTTPException, status, Query
from sqlalchemy.orm import Session
from typing import List, Optional

from app.database import get_db
from app.schemas.product import ProductResponse

router = APIRouter()


@router.get("/", response_model=List[ProductResponse], summary="获取商品列表")
async def get_products(
    keyword: Optional[str] = Query(None, description="搜索关键词"),
    category: Optional[str] = Query(None, description="商品分类"),
    min_price: Optional[float] = Query(None, description="最低价格"),
    max_price: Optional[float] = Query(None, description="最高价格"),
    skip: int = Query(0, description="跳过数量"),
    limit: int = Query(100, description="返回数量"),
    db: Session = Depends(get_db)
):
    """获取商品列表"""
    # TODO: 实现商品列表查询
    return []


@router.get("/{product_id}", response_model=ProductResponse, summary="获取商品详情")
async def get_product(
    product_id: str,
    db: Session = Depends(get_db)
):
    """获取商品详情"""
    # TODO: 实现商品详情查询
    raise HTTPException(
        status_code=status.HTTP_404_NOT_FOUND,
        detail="商品不存在"
    )


@router.get("/search/latest", response_model=List[ProductResponse], summary="获取最新商品")
async def get_latest_products(
    limit: int = Query(20, description="返回数量"),
    db: Session = Depends(get_db)
):
    """获取最新上架的商品"""
    # TODO: 实现最新商品查询
    return []


@router.post("/refresh", summary="手动刷新商品数据")
async def refresh_products(
    keyword: str = Query(..., description="搜索关键词"),
    db: Session = Depends(get_db)
):
    """手动触发商品数据刷新"""
    # TODO: 实现手动刷新逻辑
    return {"message": "商品数据刷新任务已启动"}
